<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="apple-touch-fullscreen" content="YES">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta http-equiv="Cache-Control"
	content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>我的票夹</title>
<!--引入pageSlider所需样式表-->
<link rel="stylesheet" type="text/css" href="css/pageSlider.css">
<!--引入zepto.js-->
<script type="text/javascript" src="js/zepto.js"></script>

<script type="text/javascript" src="js/jweixin-1.4.0.js"></script>

<!--引入pageSlider.js文件-->
<script type="text/javascript" src="js/pageSlider.js"></script>
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<!-- <script type="text/javascript" src="js/jquery.rotate.js"></script> -->
<script src="js/DD_roundies_min.js"></script>

<style type="text/css">

	* {
    margin: 0;
    padding: 0;
}

</style>
</head>


<body>

	<div style="width: 100%;overflow-y:scroll">
		<div align="left" onclick="back()" style="background-color: #7275ff;color: white;line-height: 3rem;width: 100%;">&lt;返回</div>

		<div id="invoiceItem">
			<table id="invoiceItemTables" style="width: 100%">
					
			</table>
		</div>
	</div>

	<div style="margin-left: 2px;">
		<table style="width: 100%; display: none" id="detailTable" onclick="hideTable()">
			<tr style="line-height: 3rem">
				<td align="left">发票类型</td>
				<td id="invoiceType"></td>
			</tr>
			<tr  style="line-height: 3rem">
				<td align="left">开票方</td>
				<td id="kpf"></td>
			</tr>
			<tr  style="line-height: 3rem">
				<td align="left">发票抬头</td>
				<td id="fptt"></td>
			</tr>
			<tr  style="line-height: 3rem">
				<td align="left">开票日期</td>
				<td id="kprq"></td>
			</tr>
			<tr  style="line-height: 3rem">
				<td align="left">发票代码</td>
				<td id="fpdm"></td>
			</tr>
			<tr  style="line-height: 3rem">
				<td align="left">发票号码</td>
				<td id="fphm"></td>
			</tr>
			<tr  style="line-height: 3rem">
				<td align="left">发票金额</td>
				<td id="fpje"></td>
			</tr>
			<tr  style="line-height: 3rem">
				<td align="left">下载地址</td>
				<td id="xzdz"></td>
			</tr>
		</table>
	</div>
	<div style="display: inline;line-height: 3rem;background-color: #e7e7e8;position:fixed; bottom:0;width: 100%">
			<table style="width: 100%">
				<tr>
					<td align="center" style="border-right: 1px solid;border-color:#c2c2c2">首页</td>
					<td align="center" style="border-right: 1px solid;border-color:#c2c2c2">打印</td>
					<td align="center" style="border-right: 1px solid;border-color:#c2c2c2">查验</td>
					<td align="center">我的</td>
				</tr>
			</table>
	</div>
		
	<script type="text/javascript">
		$(document).ready(function() {
			var link = location.href;
			var timestamp = Date.parse(new Date());
			var noncestr = Math.random().toString(36).substr(2);
			// 微信认证信息
			var link = location.href;
			$.ajax({
			　　url: "/recruit/restful/signature/getSign",//后台给你提供的接口
			　　type: "GET",
			　　data: {"link":link,"timestamp":timestamp,"noncestr":noncestr},
			　　async: false,
			　　contentType: "application/json; charset=utf-8",
			　　dataType: "json",
			　　success: function (data) {
			　　　　wx.config({
			　　　　　　debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来
			　　　　　　appId: data.appId, // 必填，公众号的唯一标识
			　　　　　　timestamp: data.timestamp, // 必填，生成签名的时间戳
			　　　　　　nonceStr: data.nonceStr, // 必填，生成签名的随机串
			　　　　　　signature: data.signature,// 必填，签名，见附录1
			　　　　　　jsApiList: [
			　　　　　　　　    "playVoice",//分享朋友圈接口
			        	"getLocation",
			        	"getNetworkType",
			        	"scanQRCode",
			        	"chooseInvoice"
                    ]
			　　　　});
			　　　　wx.error(function (res) {
			　　　　　　var test=res;
			　　　　});
				  wx.ready(function(res){
					  
					  // 检查API 权限
					 /*  wx.checkJsApi({
						    jsApiList: ['chooseInvoice'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
						    success: function(res) {
						    	//var test="";
						    	//alert(res);
						    // 以键值对的形式返回，可用的api值true，不可用为false
						    // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
						    }
					  }); */
					  
					  
					  // 地理位置
					  /* wx.getLocation({
						  type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
						  success: function (res) {
						  var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
						  var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
						  var speed = res.speed; // 速度，以米/每秒计
						  var accuracy = res.accuracy; // 位置精度
						  }
					  }); */
					  
					  // 网络类型
					 /*  wx.getNetworkType({
						  success: function (res) {
						  var networkType = res.networkType; // 返回网络类型2g，3g，4g，wifi
						  }
					  }); */
					  
					  wx.invoke("chooseInvoice", {
						  'timestamp': data.timestamp, // 卡券签名时间戳
                          'nonceStr':   data.nonceStr, // 卡券签名随机串
                          'signType': 'SHA1', // 签名方式，默认'SHA1'
                          'cardSign':  data.signature // 卡券签名
					  },function(res){
						 // json 串，转对象
						 var invoiceInfo = JSON.parse(res.choose_invoice_info); 
						 for(var i in invoiceInfo ){
							 var arryay =JSON.stringify(invoiceInfo[i]);
							 var card =JSON.parse(arryay);
							 var cardId =card['card_id'];
							 var encrypt_code =card['encrypt_code'];
							 getInvoIce(cardId,encrypt_code);
						 }
					  });
					  
					 // 扫描二维码
					  wx.scanQRCode({
						  needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
						  scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
						  success: function (res) {
							  
							  var arryay =JSON.stringify(res);
							  alert(arryay);
						      //var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
						  
						  }
					  });
				  });
			　　},
			　　error: function (error) {
			　　　　var test="";
			　　}
			});
		});
		
		 var html="";
		 function getInvoIce(cardId,encrypt_code){
			$.ajax({ 
				 type: "GET",
				 url: "/recruit/restful/signature/getInvoiceInfo",
				 data: {"card_id":cardId,"encrypt_code":encrypt_code},
				 dataType: "json",
				 success: function(data){
					 var invoiceDetail =JSON.parse(data.obj);
					 var userInfo =invoiceDetail['user_info'];
					 var date=getFormatDateByLong(userInfo['billing_time'],'yyyy-MM-dd hh:mm:ss');
					 var type =invoiceDetail['type'];
					 var payee =invoiceDetail['payee'];
					 var fee =userInfo['fee']/100;
					 var billing_no =userInfo['billing_no'];
					 var billing_code =userInfo['billing_code'];
					 var pdf_url =userInfo['pdf_url'];
					 var title =userInfo['title'];
					 html=html+"<tr onclick=\"showDetailLocal('"+type+"','"+payee+"','"+fee+"','"+date+"','"+billing_no+"','"+billing_code+"','"+pdf_url+"','"+title+"')\" style=\"line-height: 2rem;background-color: #ededed;width:100%;cursor: pointer\"><td style=\"margin-left: 1rem\" ><div>"+invoiceDetail['payee']+"</div><div>金额："+userInfo['fee']/100+"&nbsp;时间："+date+"</div></td></tr>";
					 $("#invoiceItemTables").html(html);
				 },
				 error: function(XMLHttpRequest, textStatus, errorThrown) {
					 
				 }
			});
		 }
		
		/** 返回首页 **/
		function back(){
			var protocol =window.location.protocol;
			var host =window.location.host;
			var path =window.location.search;
			window.location.href="/recruit/h5/print/print.html";
		}
		
		// 发票本地详情
		function showDetailLocal(type,payee,fee,billing_time,billing_no,billing_code,pdf_url,title){
			$("#invoiceItemTables").hide();
			$("#detailTable").show();
			$("#invoiceType").html(type);
			$("#kpf").html(payee);
			$("#fptt").html(title);
			$("#kprq").html(billing_time);
			$("#fpdm").html(billing_no);
			$("#fphm").html(billing_code);
			$("#fpje").html(fee);
			$("#xzdz").html("<a href='"+pdf_url+"'>点击下载</a>");
		}
		
		// 隐藏详情
		function hideTable(){
			$("#invoiceItemTables").show();
			$("#detailTable").hide();
		}
		// 发票详情
		function showDetail(cardId,encrypt_code){
			window.location.href="/recruit/h5/print/invoiceFetail.html?cardId="+cardId+"&encrypt_code="+encrypt_code;
		}
		function dateFormat(longTypeDate){
			 var dateTypeDate = "";  
			 var date = new Date();  
			 date.setTime(longTypeDate);  
			 dateTypeDate += date.getFullYear(); //年  
			 dateTypeDate += "-" + getMonth(date); //月  
			 dateTypeDate += "-" + getDay(date); //日  
			 return dateTypeDate; 
		} 
		
		Date.prototype.format = function (format) { 
			var o = { 
				"M+": this.getMonth() + 1, 
				"d+": this.getDate(), 
				"h+": this.getHours(), 
				"m+": this.getMinutes(), 
				"s+": this.getSeconds(), 
				"q+": Math.floor((this.getMonth() + 3) / 3), 
				"S": this.getMilliseconds() 
			} 
			if (/(y+)/.test(format)) { 
				format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); 
			} 
			for (var k in o) { 
				if (new RegExp("(" + k + ")").test(format)) { 
				format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); 
				} 
			} 
				return format; 
			}
		
		function getFormatDateByLong(l, pattern) { 
		   return getFormatDate(new Date(l*1000), pattern); 
		} 
		
		function getFormatDate(date, pattern) { 
			if (date == undefined) { 
				date = new Date(); 
			} 
			if (pattern == undefined) { 
				pattern = "yyyy-MM-dd hh:mm:ss"; 
			} 
			return date.format(pattern); 
		} 
	</script>

</body>
</html>